/**
 * @Title: DishEmptyAdapter.java
 * @Project DCB
 * @Package com.pdw.dcb.ui.adapter
 * @Description: 沽清列表
 * @author zeng.ww
 * @date 2012-12-10 下午04:37:29
 * @version V1.0
 */
package com.netstar.ui.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.netstar.R;
import com.netstar.model.MtvModel;
import com.netstar.util.StringUtil;

/**
 * Mtv适配器
 * 
 * @author zou.sq
 * @since 2013-03-12 下午04:37:29
 * @version 1.0
 */
public class MtvAdapter extends BaseAdapter {
	private List<MtvModel> mMtvList;
	private Context mContext;

	/**
	 * 实例化对象
	 * 
	 * @param context
	 *            上下文
	 * @param dataList
	 *            数据列表
	 */
	public MtvAdapter(Context context, List<MtvModel> dataList) {
		this.mContext = context;
		this.mMtvList = dataList;
	}

	@Override
	public int getCount() {
		if (mMtvList != null && !mMtvList.isEmpty()) {
			return mMtvList.size();
		}
		return 0;
	}

	@Override
	public MtvModel getItem(int position) {
		if (mMtvList != null) {
			return mMtvList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		viewHode view = new viewHode();
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.mtv_item, null);
			view.mTitle = (TextView) convertView.findViewById(R.id.tv_mtv_item);
			view.mIcon = (ImageView) convertView.findViewById(R.id.iv_mtv_icon);
			convertView.setTag(view);
		} else {
			view = (viewHode) convertView.getTag();
		}
		MtvModel model = mMtvList.get(position);
		String fileName = model.fileName;
		Bitmap fileIcon = model.bitmap;
		if (!StringUtil.isNullOrEmpty(fileName)) {
			view.mTitle.setText(model.fileName);
		}
		if (null != fileIcon) {
			view.mIcon.setImageBitmap(fileIcon);
		}
		return convertView;
	}

	class viewHode {
		TextView mTitle;
		ImageView mIcon;
	}
}
